namespace NICWebApi.Extensions.Caching.Options;

/// <summary>
/// 缓存选项配置
/// </summary>
public class CachingOptions
{
    /// <summary>
    /// 缓存键前缀
    /// </summary>
    public string KeyPrefix { get; set; } = "NICWebApi";

    /// <summary>
    /// 缓存键分隔符
    /// </summary>
    public string KeySeparator { get; set; } = ":";

    /// <summary>
    /// 默认缓存过期时间（秒）
    /// </summary>
    public int DefaultExpirationSeconds { get; set; } = 300;

    /// <summary>
    /// 是否启用分布式缓存
    /// </summary>
    public bool UseDistributedCache { get; set; } = false;

    /// <summary>
    /// 是否启用内存缓存
    /// </summary>
    public bool UseMemoryCache { get; set; } = true;

    /// <summary>
    /// Redis连接字符串，当UseDistributedCache=true且此值不为空时使用Redis作为分布式缓存
    /// </summary>
    public string RedisConnectionString { get; set; }

    /// <summary>
    /// 是否使用序列化，对于分布式缓存默认为true
    /// </summary>
    public bool UseSerializer { get; set; } = false;

    /// <summary>
    /// 缓存提供程序特定选项
    /// </summary>
    public Dictionary<string, object> ProviderSpecificOptions { get; set; } = new Dictionary<string, object>();

    /// <summary>
    /// 缓存命中统计
    /// </summary>
    public bool EnableStatistics { get; set; } = false;

    /// <summary>
    /// 缓存项目大小限制（字节），仅对内存缓存有效
    /// </summary>
    public long? SizeLimit { get; set; }
}

/// <summary>
/// 内存缓存选项
/// </summary>
public class MemoryCacheOptions
{
    /// <summary>
    /// 是否启用内存缓存，默认为true
    /// </summary>
    public bool Enabled { get; set; } = true;

    /// <summary>
    /// 内存缓存大小限制（以MB为单位），默认为100MB
    /// 设置为0表示不限制
    /// </summary>
    public int SizeLimitInMB { get; set; } = 100;

    /// <summary>
    /// 内存缓存编译压缩阈值，默认为0.8（80%）
    /// </summary>
    public double CompactionPercentage { get; set; } = 0.8;

    /// <summary>
    /// 内存缓存扫描频率（以秒为单位），默认为60秒
    /// </summary>
    public int ExpirationScanFrequencyInSeconds { get; set; } = 60;
}

/// <summary>
/// 分布式缓存选项
/// </summary>
public class DistributedCacheOptions
{
    /// <summary>
    /// 是否启用分布式缓存，默认为false
    /// </summary>
    public bool Enabled { get; set; } = false;

    /// <summary>
    /// 分布式缓存提供程序类型
    /// </summary>
    public DistributedCacheProviderType ProviderType { get; set; } = DistributedCacheProviderType.Memory;

    /// <summary>
    /// Redis连接字符串
    /// </summary>
    public string RedisConnectionString { get; set; } = "localhost:6379";

    /// <summary>
    /// Redis实例名称
    /// </summary>
    public string RedisInstanceName { get; set; } = "NICWebApi";

    /// <summary>
    /// 是否启用数据压缩，默认为false
    /// </summary>
    public bool EnableCompression { get; set; } = false;
}

/// <summary>
/// 分布式缓存提供程序类型
/// </summary>
public enum DistributedCacheProviderType
{
    /// <summary>
    /// 内存分布式缓存
    /// </summary>
    Memory = 0,

    /// <summary>
    /// Redis分布式缓存
    /// </summary>
    Redis = 1,

    /// <summary>
    /// SQL Server分布式缓存
    /// </summary>
    SqlServer = 2
}